package com.spring.demo.config;

import java.util.Arrays;
import java.util.Set;

import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar{

	/**
	 * AnnotationMetadata : 导入类上的注解
	 * BeanDefinitionRegistry : spring bean注册表
	 */
	public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
		System.out.println("1-------------------");
		// 获取所有注解类
		Set<String> annotationTypes = importingClassMetadata.getAnnotationTypes();
		annotationTypes.stream().forEach(System.out::println);
		System.out.println("2-------------------");
		
		// 获取导入类的类名
		String className = importingClassMetadata.getClassName();
		System.out.println(className);
		System.out.println("3-------------------");
		
		String[] interfaceNames = importingClassMetadata.getInterfaceNames();
		Arrays.asList(interfaceNames).forEach(System.out::println);
		System.out.println("4-------------------");
		
		String enclosingClassName = importingClassMetadata.getEnclosingClassName();
		System.out.println(enclosingClassName);
		System.out.println("5-------------------");
		
		String[] memberClassNames = importingClassMetadata.getMemberClassNames();
		Arrays.asList(memberClassNames).forEach(System.out::println);
		System.out.println("-------------------");
	}

}
